﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using fcwms.Common;


public partial class admin_storage_store_edit : SessionManage
{
    private string action = ActionEnum.Add.ToString(); //操作类型
    private int id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        string _action = DTRequest.GetQueryString("action");
        if (!string.IsNullOrEmpty(_action) && _action == ActionEnum.Edit.ToString())
        {
            this.action = ActionEnum.Edit.ToString();//修改类型
            if (!int.TryParse(Request.QueryString["id"] as string, out this.id))
            {
                MessageBox.Jscript(this, "传输参数不正确！", "back", "Error");
                return;
            }
        }
        if (!IsPostBack)
        {
            if (action == ActionEnum.Edit.ToString())
            {
                ShowInfo(this.id);
            }
        }
    }

    #region 赋值操作==============================
    public void ShowInfo(int _id)
    {
        fcwms.BLL.dt_storage bll = new fcwms.BLL.dt_storage();
        fcwms.Model.dt_storage model = bll.GetModel(_id);
        txtStorageName.Text = model.storage_name;
        txtHearder.Text = model.hearder;
        txtTelephpne.Text = model.telephone;
        txtStorageAddr.Text = model.storage_addr;
    }
    #endregion

    #region 增加操作==============================
    private bool DoAdd()
    {
        bool result = true;
        fcwms.BLL.dt_storage bll = new fcwms.BLL.dt_storage();
        fcwms.Model.dt_storage model = new fcwms.Model.dt_storage();
        model.storage_name = txtStorageName.Text.Trim();
        model.hearder = txtHearder.Text.Trim();
        model.telephone = txtTelephpne.Text.Trim();
        model.storage_addr = txtStorageAddr.Text.Trim();
        if (bll.Add(model) < 1)
        {
            result = false;
        }
        return result;
    }
    #endregion

    #region 修改操作==============================
    private bool DoEdit(int _id)
    {
        bool result = true;
        fcwms.BLL.dt_storage bll = new fcwms.BLL.dt_storage();
        fcwms.Model.dt_storage model = bll.GetModel(_id);
        model.storage_name = txtStorageName.Text.Trim();
        model.hearder = txtHearder.Text.Trim();
        model.telephone = txtTelephpne.Text.Trim();
        model.storage_addr = txtStorageAddr.Text.Trim();
        if (!bll.Update(model))
        {
            result = false;
        }
        return result;
    }
    #endregion

    #region 保存操作==============================
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (action == ActionEnum.Edit.ToString()) //修改
        {
            //ChkAdminLevel("sys_branch", ActionEnum.Edit.ToString()); //检查权限
            if (!DoEdit(this.id))
            {
                MessageBox.Jscript(this, "保存过程中发生错误啦！", "", "Error");
                return;
            }
            MessageBox.Jscript(this, "修改仓库信息成功啦", "store_list.aspx", "Success");
        }
        else //添加
        {
            //ChkAdminLevel("sys_branch", ActionEnum.Add.ToString()); //检查权限
            if (!DoAdd())
            {
                MessageBox.Jscript(this, "保存过程中发生错误啦！", "", "Error");
                return;
            }
            MessageBox.Jscript(this, "添加仓库信息成功啦", "store_list.aspx", "Success");
        }
    }
    #endregion
}